package com.baike.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baike.entity.Student;
import com.baike.service.StudentService;

/**
 * 学生信息Controller
 * @author John
 *
 */
@RestController
@RequestMapping("/student")
public class StudentController {
	
	@Resource
	private StudentService studentServiceImpl;
	
	/**
	 * 添加或者修改学生信息
	 * @param student
	 * @return
	 */
	@PostMapping("/save")
	public boolean save(@RequestBody Student student){
		try{
			studentServiceImpl.save(student);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	/**
	 * 查询学生信息
	 * @return
	 */
	@GetMapping("/list")
	public List<Student> findAll(){
		System.out.println("list--------------1002");
		return studentServiceImpl.list();
	}

	/**
	 * 根据id查询学生信息
	 * @return
	 */
	@GetMapping(value="/get/{id}")
	public Student get(@PathVariable("id") Integer id){
		return studentServiceImpl.findById(id);
	}
	
	/**
	 * 根据id删除学生信息
	 * @return
	 */
	@GetMapping(value="/delete/{id}")
	public boolean delete(@PathVariable("id") Integer id){
		try{
			studentServiceImpl.delete(id);
			return true;
		}catch(Exception e){
			return false;
		}
	}	
}
